﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlanningGIS.Util.Data;
using PlanningGIS.Util;
using PlanningGIS.Win.Controls;
using ESRI.ArcGIS.Geodatabase;

namespace PlanningGIS.Engine.Controls
{
    /// <summary>
    /// 数据列表控件
    /// </summary>
    public partial class TableGrid : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public TableGrid()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        public event BindEvent BindChanged = null;

        ///// <summary>
        ///// 获取或设置是否显示分页控件
        ///// </summary>
        //public bool PagingVisible
        //{
        //    get { return paginglist.Visible; }
        //    set { paginglist.Visible = value; }
        //}

        /// <summary>
        /// 获取或设置是否可以分组查看
        /// </summary>
        public bool GroupByRowVisiable
        {
            get { return sprgrdData.PrimaryGrid.GroupByRow.Visible; }
            set { sprgrdData.PrimaryGrid.GroupByRow.Visible = value; }
        }

        /// <summary>
        /// 获取或设置数据操作控件
        /// </summary>
        public IDbContext DbContext { get; set; }

        /// <summary>
        /// 当前页改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void paginglist_PageIndexChanged(object sender, PageEventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        public void BindData(string sql)
        {
            if (DbContext == null) return;
            DataTable dt = DbContext.GetDataTable(sql);
            sprgrdData.PrimaryGrid.DataSource = dt;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        public void SetDataSource(dynamic source)
        {
            sprgrdData.PrimaryGrid.DataSource = source;
        }
        
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public delegate void BindEvent();
}
